﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class payinfo : System.Web.UI.Page
{
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString.ToString());
    static int show = -1;
    static string sql = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        string sqls = "select * from payinfo";
        SqlDataAdapter da = new SqlDataAdapter(sqls, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        
        if (!IsPostBack)
        {
            sql = "select * from payinfo order by id asc";
            GridViewBind(sql);
        }
    }
    private void GridViewBind(string s)
    {

        SqlDataAdapter da = new SqlDataAdapter(s, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataKeyNames = new string[] { "id" };
        GridView1.DataBind();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onMouseOver", "Color=this.style.backgroundColor;this.style.backgroundColor='#fff000'");
            e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor=Color;");
            if (e.Row.Cells[6].Text == "False")
            {
                e.Row.Cells[6].Text = "<span style='color:red'>" + "未审核" + "</span>";
            }
            else
            {
                e.Row.Cells[6].Text = "<span style='color:blue'>" + "已审核" + "</span>";
            }
        }
    }
    protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
    {
        //过期
        string s = "select * from payinfo where  showday < getdate() order by id asc";
        GridViewBind(s);
        show = 1;
    }
    protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
    {
        //未过期
        string s = "select * from payinfo where  showday > getdate() order by id asc";
        GridViewBind(s);
        show = 0;
    }
    protected void RadioButton3_CheckedChanged(object sender, EventArgs e)
    {
        string s = "select * from payinfo  order by id asc";
        GridViewBind(s);
        show = -1;
    }
    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        string id = GridView1.DataKeys[e.NewSelectedIndex].Value.ToString();
        updateinfo(id, sql);
        switch (show)
        {
            case -1:
                string s2 = "select * from payinfo  order by id asc";
                GridViewBind(s2);
                break;
            case 0:
                string s3 = "select * from payinfo where  show='" + false + "' order by id asc";
                GridViewBind(s3);
                break;
            case 1:
                string s4 = "select * from payinfo where show='" + true + "' order by id asc";
                GridViewBind(s4);
                break;
        }
    }
    private void updateinfo(string id, string type)
    {
        DataSet ds = selectinfo(type, Convert.ToInt32(id));
        bool checkstate = Convert.ToBoolean(ds.Tables[0].Rows[0][6].ToString());
        string sqlst = "";
        if (checkstate)
        {
            sqlst = "update payinfo set show=0 where id = '" + id + "'";
        }
        else
        {
            sqlst = "update payinfo set show=1 where id = '" + id + "'";
        }
        conn.Open();
        SqlCommand comm = new SqlCommand(sqlst, conn);
        comm.ExecuteNonQuery();//执行
        conn.Close();
    }




    public DataSet selectinfo(string type, int id)
    {
        string sqls = "select * from payinfo where  id = '" + id + "' order by id asc";
        SqlDataAdapter da = new SqlDataAdapter(sqls, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        return ds;
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }
}